﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YunCMS.DAL;
using YunCMS.Model;
using YunCMS.BLL;
using YunCMS.Common;

namespace YunCMS.Core.Template
{
    public abstract class ModuleTemplate<T> where T : YCModule, new()
    {
        private const string FIELDS = @"[ID],[CategoryID],[Title],[Keywords],[Summary],[Description],
                                        [Author],[AddTime],[Hits],[IsPopular],[ImageUrl],[LinkUrl],
                                        [DiggTop],[DiggStep],[Source]";

        protected abstract ModuleBLL<T> BLL
        {
            get;
        }

        public IList<T> GetList(int categoryID, int top, string strwhere, string orderby)
        {
            string _where = string.Empty;
            string _order = string.Empty;

            _where = " and CategoryID=" + categoryID;

            if (!string.IsNullOrEmpty(strwhere))
            {
                _where += " and " + strwhere;
            }
            if (!string.IsNullOrEmpty(orderby))
            {
                _order += " order by " + orderby;
            }

            return BLL.GetList(top, FIELDS, _where, _order);
        }

        public IList<T> GetList(int categoryID, int top, string orderby)
        {
            return GetList(categoryID, top, Const.CQeuryWhere, orderby);
        }

        public IList<T> GetList(int categoryID, int top)
        {
            return GetList(categoryID, top, Const.CQeuryWhere, " AddTime desc");
        }

        public T GetItem(int ID)
        {
            return BLL.GetModule(ID);
        }
    }
}
